//
//  QuestionViewController.m
//  PigMarket
//
//  Created by mac on 2019/4/18.
//  Copyright © 2019 felix.pigmarket.oc. All rights reserved.
//

#pragma mark --------- 常见问题

#import "QuestionViewController.h"

@interface QuestionViewController ()<UITableViewDelegate,UITableViewDataSource>
/**
 myTableView
 */
@property (nonatomic , strong) UITableView *myTableView;
/**
 dataArr
 */
@property (nonatomic , strong) NSMutableArray *dataArr;
@end

@implementation QuestionViewController


#pragma mark - view life cycle
- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setUpTitle];
    [self setUpView];
}

#pragma mark - init method
- (void)setUpTitle {
    NSArray *titleArr = @[@"领养问题",
                          @"豚券问题",
                          @"提现问题",
                          @"申诉问题",
                          @"会员问题",
                          @"账号问题",
                          @"分割问题",
                          @"其他问题"];
    NSUInteger idx = self.type - 1;
    self.baseNavView.navTitleLabel.text = titleArr[idx];
}
- (void)setUpView {
    [self initView];
    [self initLayout];
    [self initAction];
    [self initData];
}
- (void)initView {
    [self.view addSubview:self.myTableView];
}

- (void) initLayout {
    [self.myTableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.mas_equalTo(0);
        make.top.mas_equalTo(self.baseNavView.bottom);
    }];
}

- (void) initAction {
    
}

- (void)initData {
    [[[PigMarketApi sharedInstance] getCommonQuestionsWithQuestionType:@(self.type)] subscribeNext:^(CommonQuestionsList * _Nullable detailQuestions) {
        [self.dataArr addObjectsFromArray:detailQuestions.questions];
        [self.myTableView reloadData];
    } error:^(NSError * _Nullable error) {
        
    }];
}

#pragma mark - delegate

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.dataArr.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 10;
}


- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 0.001;
}


- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    return [[UIView alloc] init];
}


- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    return [[UIView alloc] init];
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *identifier = @"identifier";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:identifier];
    }
    CommonQuestions *model = self.dataArr[indexPath.row];
    cell.textLabel.text = model.questionTitle;
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    return cell;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
}


#pragma mark - target action

#pragma mark - private method

#pragma mark - getter and setter
- (UITableView *)myTableView {
    if (!_myTableView) {
        _myTableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];
        _myTableView.rowHeight = 54;
        _myTableView.delegate = self;
        _myTableView.dataSource = self;
    }
    return _myTableView;
}


- (NSMutableArray *)dataArr {
    if (!_dataArr) {
        _dataArr = [[NSMutableArray alloc] init];
    }
    return _dataArr;
}

@end
